home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / mgr / sparcmgr / demo1.zoo / demo / icon / icontoc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-01-24  |  2.3 KB  |  111 lines

  1. /*                        Copyright (c) 1988 Bellcore
  2.  *                            All Rights Reserved
  3.  *       Permission is granted to copy or use this program, EXCEPT that it
  4.  *       may not be sold for profit, the copyright notice must be reproduced
  5.  *       on copies, and credit should be given to Bellcore where it is due.
  6.  *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  7.  */
  8. /*    $Header: icontoc.c,v 4.2 88/07/11 10:12:56 sau Exp $
  9.     $Source: /tmp/mgrsrc/demo/icon/RCS/icontoc.c,v $
  10. */
  11. static char    RCSid_[] = "$Source: /tmp/mgrsrc/demo/icon/RCS/icontoc.c,v $$Revision: 4.2 $";
  12.  
  13. /* comnvert mgr icon to "c" */
  14.  
  15.  
  16. static char    *cmd;
  17.  
  18. #include <stdio.h>
  19. #include "bitmap.h"
  20.  
  21. main(argc,argv)
  22. int argc;
  23. char **argv;
  24. {
  25.  
  26.     cmd = *argv;
  27.     argv++; argc--;
  28.     if (argc < 1)
  29.         usage();
  30.  
  31.     /*
  32.     if( EQ( *argv, "-a" ) ) {
  33.         if( argc >= 2 )
  34.             usage();
  35.         argv++; argc--;
  36.         align = atoi( *argv );
  37.         argv++; argc--;
  38.         }
  39.         */
  40.  
  41.     if( argc < 1 )
  42.         usage();
  43.  
  44.     for(  ; argc > 0;  argv++, argc-- )
  45.         dofile( *argv );
  46.  
  47.     exit(0);
  48.     }
  49.  
  50.  
  51. static
  52. dofile( filename )
  53. char    *filename;
  54. {
  55.     FILE        *filep;
  56.     register unsigned char    *cp, *endp;
  57.     register int    i;
  58.     BITMAP        *map, *bitmapread();
  59.     char        *name;
  60.     char        *rindex();
  61.  
  62.     if ((filep = fopen(filename,"r")) == NULL) {
  63.         fprintf(stderr,"%s: Can\'t open %s\n",cmd,filename);
  64.         exit(2);
  65.         }
  66.     
  67.     if( !(map = bitmapread( filep )) ) {
  68.         fprintf(stderr,"%s: %s is not a bitmap file\n",cmd,filename);
  69.         fclose(filep);
  70.         exit(3);
  71.         }
  72.     fclose(filep);
  73.  
  74.     /* print out header */
  75.  
  76.     if (name = rindex(filename,'/'))
  77.         name++;
  78.     else 
  79.         name = filename;
  80.  
  81.     printf("\
  82. \n/*    bitmap for \"%s\", %d wide, %d high, %d bit%s deep, %d bit aligned\n\
  83. */\n",
  84.         name, BIT_WIDE(map), BIT_HIGH(map),
  85.         BIT_DEPTH(map), BIT_DEPTH(map) > 1 ? "s" : "", BITS+1);
  86.  
  87.     printf("bit_static(%s, %d, %d, %s_data, 1);\n", name,
  88.         BIT_WIDE(map), BIT_HIGH(map), name);
  89.  
  90.     /* print out data */
  91.  
  92.     cp = (unsigned char *)BIT_DATA(map);
  93.     endp = cp + BIT_SIZE(map);
  94.     printf("char %s_data[%d] = {\n\t", name, endp - cp);
  95.     for( i=1;  cp < endp; cp++, i++ )
  96.         printf("0%3.3o%s", *cp, i%10 ? ", " : ",\n\t");
  97.     printf("\n\t};\n");
  98.     free((char*)map);
  99.     }
  100.  
  101. static
  102. usage()
  103. {
  104.     fprintf( stderr,"Usage: %s <icon_file> ...  > <icon>.c\n", cmd );
  105. /*
  106.     fputs( "\
  107. -a n    Create bit map aligned to n bits.  n may be 8, 16, or 32.\n", stderr );
  108. */
  109.     exit(1);
  110. }
  111.